<?php
/**
 * @filename IndexController.php 
 * @encoding UTF-8 
 * @author KangShuAn
 * @datetime 2009-12-19 17:18:47
 * @version 1.0
 * @Description
 */
class IndexController extends FrontController
{
    /**
     * 修改密码
     */
    public function actionChange()
    {
        $this->smarty->display('index/change.tpl');
    }
    /**
     * 修改
     */
    public function actionDochange(){
        $network_pwd = $this->post('network_pwd');
        $network_pwd1 = $this->post('network_pwd1');
        if (empty($network_pwd)) {
            $this->jump('密码不能为空');
        }
        if ($network_pwd != $network_pwd1) {
            $this->jump('两次密码不一致');
        }
        $network = new NetWork();
        $info = $network->findByPk($this->network_id);
        if ($info['network_pwd'] == $network_pwd) {
            $this->jump('与原密码相同');
        }
        if ($network->updateByPk($this->network_id, array('network_pwd' => $network_pwd, 'network_oldpwd' => $info['network_pwd']))) {
            $this->jump('修改成功');
        }
        $this->jump('修改失败');
    }
    /**
     * 网点问卷列表
     */
    public function actionAttach(){
        $netattach = new NetworkAttach();
        $criteria = new CDbCriteria();
        $criteria->addColumnCondition(array('network_id' => $this->network_id));
        $criteria->addColumnCondition(array('status' => 1));
        $total = $netattach->count($criteria);
        $criteria->limit = 20;
        $criteria->offset = ($p - 1) * 20;
        $criteria->order = 'create_time desc';
        $list = $netattach->findAll($criteria);

        $page = new Page($total, 20);
        $this->smarty->assign('list', $list);
        $this->smarty->assign('network_id', $this->network_id);
        $this->smarty->assign('page', $page->style1());
        $this->smarty->assign('action','attach');
        $this->smarty->display('index/attach.tpl');
    }
    /**
     * 以中文名下载附件
     */
    public function actionDown()
    {
        $na_id = (int)$this->get('na_id');
        $attach = NetworkAttach::model()->findByPk($na_id);
        if (!$attach) 
        {
            echo '无附件';exit;
        }
        $attach_name = $attach->url;
        if ($attach->nba_id) //网点通用
        {
            $file = dirname(Yii::app()->basePath).'/assets/network_zip/bank/'.$attach_name;
        } else {
            $file = dirname(Yii::app()->basePath).'/assets/network_zip/'.$attach->network_id.'/'.$attach_name;
        }
        
        if (!file_exists($file)) 
        {
            echo '无附件';exit;
        }
        header("Content-type: application/octet-stream");
        header("Accept-Ranges: bytes");
        header("Content-Type:application/force-download");
        header("Content-Transfer-Encoding:binary");
        header('Content-Type: application/zip; charset=utf-8'); 
        $userbrowser = $_SERVER['HTTP_USER_AGENT']; 
        if ( preg_match( '/MSIE/i', $userbrowser ) ) { 
            header("Content-Disposition:attachment;filename=".urlencode($attach->zip_name).".zip");
        } else { 
            header("Content-Disposition:attachment;filename=".$attach->zip_name.".zip");
        } 
        
        readfile($file);
        exit;
        
        
    }
}